package com.hbnu.system.controller;


import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.Workauthor;
import com.hbnu.system.service.IWorkauthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/workauthor")
@Api(tags = "著作的作者管理")
public class WorkauthorController {

    @Autowired
    private IWorkauthorService iWokrauthorService;

    @ApiOperation("新增著作作者")
    @PostMapping("/addauthor")
    public Rest<String> addAuthor(@RequestBody Workauthor workauthor){
        boolean ba = iWokrauthorService.addWorkAuthor(workauthor);
        return ba ? Rest.success() : Rest.failed();
    }

    @ApiOperation("删除作者信息")
    @GetMapping("/deleteauthor")
    public Rest<String> delete(String id){
        boolean ba1 = iWokrauthorService.deleteWorkAuthor(id);
        return ba1?Rest.success():Rest.failed();
    }

    @ApiOperation("修改作者信息")
    @PostMapping("/updateauthor")
    public Rest<String> updateAuthor(@RequestBody Workauthor workauthor){
        boolean ba2=iWokrauthorService.updateWorkAuthor(workauthor);
        return ba2?Rest.success():Rest.failed();
    }

    @ApiOperation("搜索作者信息")
    @GetMapping("/selectauthor")
    public Rest<List<Workauthor>> selectAuthor(String id){
        List<Workauthor> pa=iWokrauthorService.pageworkauthor(id);
        return Rest.success(pa,pa.size());
    }

    @ApiOperation("校级管理员修改作者系数")
    @PostMapping("/upWorkAuthor")
    public Rest<Boolean> upWorkAuthor(@RequestBody Workauthor workAuthor){
        boolean update = iWokrauthorService.upWorkAuthor(workAuthor);
        return update ? Rest.success() : Rest.failed();
    }

}

